package ptij.vocoder.baseModel.closed_loop;

import ptolemy.actor.*;
import ptolemy.kernel.*;
import ptolemy.kernel.util.*;
import ptolemy.data.ObjectToken;
import ptolemy.data.type.*;

import ptij.vocoder.baseModel.*;

//////////////////////////////////////////////////////////////////////////
//// ComputeCN
/**

@author Ivan Jeukens
@version v 0.1 07/08/2003
*/
public class ComputeCN extends TypedAtomicActor {

    public ComputeCN(CompositeEntity container, String name) throws
            IllegalActionException, NameDuplicationException {
        super(container, name);

        res = new TypedIOPort(this, "res", true, false);
        res.setTypeEquals(BaseType.OBJECT);

        c_gain = new TypedIOPort(this, "c_gain", false, true);
        c_gain.setTypeEquals(BaseType.OBJECT);

        trigger = new TypedIOPort(this, "trigger", true, false);
    }

    ///////////////////////////////////////////////////////////////////
    ////                     ports and parameters                  ////

    // Input ports
    public TypedIOPort res;
    public TypedIOPort trigger;

    // Output Ports
    public TypedIOPort c_gain;

    ///////////////////////////////////////////////////////////////////
    ////                         public methods                    ////

    public void initialize() throws IllegalActionException {
        super.initialize();
    }

    public void fire() throws IllegalActionException {
        if(trigger.hasToken(0)) {
            trigger.get(0);

            ObjectToken obj = (ObjectToken) res.get(0);
            Short [] arg1 = (Short []) obj.getValue();

            Short resp = _compute_cn_gain(arg1);
            obj = new ObjectToken(resp);
            c_gain.broadcast(obj);
        }
    }

    ///////////////////////////////////////////////////////////////////
    ////                         private methods                   ////

    private Short _compute_cn_gain(Short [] res2) {

        return new Short((short)1);
    }

    ///////////////////////////////////////////////////////////////////
    ////                         private variables                 ////

}
